﻿@using WI.CandidateManager.Common.Data.Entities
@using CandidateManager.ViewsParams
@using strconsts = WI.CandidateManager.Common.Data.Constants.StringConstants
@model System.Collections.IEnumerable

@{
    var parameters = (GenericGetParams)ViewData[strconsts.Parameters];
}

@if (parameters.EnableCreate)
{
    <p>@Html.ActionLink("+ Create New", parameters.CreateActionName, parameters.ControllerName, null, new { @class = "common-btn BlueColor" })</p>
}

<table class="bordered">
    <thead>
        <tr>
            @if (parameters.EnableEdit)
            {
                <th>Edit</th>
            }

            @foreach (var propertyName in parameters.PropertiesToDisplay)
            {
                if (Model.GetType().GenericTypeArguments[0].GetProperties().Any(p => p.Name == propertyName))
                {
                <th>@propertyName</th>
                }
            }

            @if (parameters.EnableDelete)
            {
                <th>Delete</th>
            }
        </tr>
    </thead>

    @foreach (EntityBase record in Model)
    {
        <tr>
            @if (parameters.EnableEdit)
            {
                <td class="Center column-detail">
                    @Html.ActionLink("Edit", parameters.EditActionName, parameters.ControllerName, new { id = record.Id }, new { @class = "common-btn BlueColor" })
                </td>
            }

            @foreach (var propertyName in parameters.PropertiesToDisplay)
            {
                <td>
                    @record.GetType().GetProperties().Single(p => p.Name == propertyName).GetValue(record).ToString()
                </td> 
            }

            @if (parameters.EnableDelete)
            {
                <td class="Center column-detail">
                    @Html.ActionLink("Delete", parameters.DeleteActionName, parameters.ControllerName, new { id = record.Id }, new { @class = "common-btn BlueColor" })
                </td>
            }
        </tr>
    }
</table>
